<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>配合额外参数使用$emit</title>
    <script src='/js/vue.js'></script>
    <style>
        #app{
            width: 600px;
            margin: 40px auto;
        }
        .outer{
            display: flex;
            margin-bottom: 20px;
        }
        .inner{
            padding: 0 10px;
            text-align: center;
            min-width: 100px;
            border-bottom: 1px solid #000;
            font-weight: bold;
            color: red;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="outer">今天天气不错，我准备
            <div class="inner">{{activity}}</div>
        </div>
        <advice @advice="receiveAdvice"></advice> 
    </div>

</body>
    
<script>
    Vue.component('advice',{
        data() {
            return{
                arr:['打篮球','野炊','游泳','宅在家','复习迎考']
            }
        },
        template:'<button @click="giveAdvice">给出建议</button>',
        methods:{
            giveAdvice: function(){
                let msg = this.arr[Math.floor(Math.random() * this. arr.length)]
                this.$emit('advice', msg)
            }
        }
    })

    let app = new Vue({
     el: '#app',
     data: {
        activity: ''
     },
     methods:{
        receiveAdvice(msg){
            this.activity = msg
        }
    }
    });
</script>
</html>